<?PHP
/*
*	File: 		includes/forum/board.class.php
*	Use:		Board Class
*	Functions:	
*
*	Misc:		Class: users
*				Description: handles querys about users (logins, profile changes, etc)
*
*	Coder:		Andrew Thorne, UK
*	Copyright:	No part of this code may be used for any purpose other 
*				than the original intended purpose without prior written 
*				permission of Andrew Thorne. 
*				Use for any other purpose is expressly prohibited by law, 
*				and may result in civil and criminal penalties.
*
*	Contact:	omgrofl@hotmail.co.uk
*
*/
	

class board {

	
	/* 
	*
	* Function: getBoard
	*
	*/
	public function getBoard($db, $board_id){
		
		$prefix = $db->getPrefix();	

		if(is_numeric($_SESSION['groupid']) && ($_SESSION['groupid']=="" || !isset($_SESSION['groupid']))){
			$groupId=0;	
		} else {
			$groupId=$db->prep($_SESSION['groupid']);
		}
		
		if(is_numeric($board_id)){
			return $db->query("SELECT * FROM ".$prefix."forum_board a INNER JOIN ".$prefix."forum_perms_cat b ON a.cat_id=b.cat_id WHERE board_active=1 AND board_id=".$db->prep($board_id)." AND view=1 AND user_group_id=".$groupId." ");
		} else {
			return false;
		}
		
	}
	
	/* 
	*
	* Function: getAllBoards
	*
	*/
	public function getAllBoards($db, $cat_id){
		
		$prefix = $db->getPrefix();	

		if(is_numeric($_SESSION['groupid']) && ($_SESSION['groupid']=="" || !isset($_SESSION['groupid']))){
			$groupId=0;	
		} else {
			$groupId=$db->prep($_SESSION['groupid']);
		}
		if(is_numeric($cat_id)){
			return $db->query("SELECT * FROM ".$prefix."forum_board a INNER JOIN ".$prefix."forum_perms_board b ON a.board_id=b.board_id WHERE a.board_active=1 AND a.cat_id=".$cat_id." AND view=1 AND user_group_id=".$groupId." ORDER BY a.board_order ASC");		
		} else {
			return false;	
		}
		
	}
	
	/* 
	*
	* Function: getBread
	*
	*/
	public function getBread($db, $board_id){
		$prefix = $db->getPrefix();	
		
		$prefix = $db->getPrefix();	

		if(is_numeric($_SESSION['groupid']) && ($_SESSION['groupid']=="" || !isset($_SESSION['groupid']))){
			$groupId=0;	
		} else {
			$groupId=$db->prep($_SESSION['groupid']);
		}
		if(is_numeric($board_id)){
			$sql = "SELECT * FROM ((".$prefix."forum_board a INNER JOIN ".$prefix."forum_perms_board b ON a.board_id=b.board_id) INNER JOIN ".$prefix."forum_category c ON a.cat_id=c.cat_id) INNER JOIN ".$prefix."forum_perms_cat d ON c.cat_id=d.cat_id WHERE a.board_id=".$board_id." AND d.view=1 AND b.view=1 AND d.user_group_id=".$groupId." AND b.user_group_id=".$groupId;
			$result = $db->query($sql);	
			if(mysql_num_rows($result)==1){
				while($row = mysql_fetch_object($result)){
					$bread['cat_id'] = $row->cat_id;
					$bread['boa_id'] = $row->board_id;
					$bread['cat_name'] = $row->cat_name;
					$bread['boa_name'] = $row->board_name;
					return $bread;
				}
			} else {
				return false;	
			}
		} else {
			return false;	
		}
	}
	
	/* 
	*
	* Function: getLastPost
	*
	*/
	public function getLastPost($db, $board_id){
		$prefix = $db->getPrefix();	
		if(is_numeric( $board_id)){
			return $db->query("SELECT * FROM ".$prefix."forum_post a INNER JOIN ".$prefix."forum_topic b ON a.topic_id=b.topic_id WHERE b.board_id=".$db->prep($board_id)." ORDER BY a.post_time DESC LIMIT 1");
		} else {
			return false;	
		}
	}
	
}
?>